﻿Imports System.Data
Imports System.Data.SqlClient
Module Module1

    Sub Main()
        Dim builder As New SqlConnectionStringBuilder
        builder.DataSource = "(local)"
        builder.InitialCatalog = "cursodb"
        builder.IntegratedSecurity = True
        Dim con As New SqlConnection(builder.ConnectionString)
        Dim cmd As New SqlCommand("select * from alumnos", con)
        Dim adp As New SqlDataAdapter(cmd)
        Dim cb As New SqlCommandBuilder(adp)
        adp.InsertCommand = cb.GetInsertCommand
        adp.UpdateCommand = cb.GetUpdateCommand
        adp.DeleteCommand = cb.GetDeleteCommand
        Dim ds As New DataSet
        adp.Fill(ds, "Alumnos")
        For Each row As DataRow In ds.Tables(0).Rows
            Console.WriteLine(row(1))
        Next
        Dim r As DataRow = ds.Tables(0).NewRow
        `(0) = Guid.NewGuid()
        r(1) = "maria"
        r(2) = 4
        ds.Tables(0).Rows.Add(r)

        'ds.Tables(0).Rows.RemoveAt(0)


        ' ds.Tables(0).Rows(0)("nombre") = "datasetname"

        Dim at = ds.Tables(0).GetChanges(System.Data.DataRowState.Added)
        Dim ut = ds.Tables(0).GetChanges(System.Data.DataRowState.Modified)
        Dim dt = ds.Tables(0).GetChanges(System.Data.DataRowState.Deleted)
        adp.UpdateBatchSize = 30
        If (at IsNot Nothing) Then
            adp.Update(at)
        End If
        If (ut IsNot Nothing) Then
            adp.Update(ut)
        End If
        If (dt IsNot Nothing) Then
            adp.Update(dt)
        End If
        ds.Tables(0).AcceptChanges()







    End Sub

End Module
